package tau_sadna.tau_map;

import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class RestartRequest extends RelativeLayout{
	protected MainActivity mainActivity;

	public RestartRequest(MainActivity main, String text, String buttonText) {
		super(main);
		
		mainActivity = main;
		
		setBackgroundColor(Color.WHITE);
		
		
		TextView textView = new TextView(main);
		textView.setId(831);
		textView.setText(text);
		textView.setGravity(Gravity.CENTER);
		textView.setTextSize(20);
		
		ImageView button = new ImageView(main);
		button.setImageDrawable(main.getResources().getDrawable(R.drawable.red_x));
		button.setId(829);
		OnClickListener listener = new OnClickListener(){
			@Override
			public void onClick(View v) {
				mainActivity.closeCurrentWindow();
			}
			
		};
		button.setOnClickListener(listener);
		
		// restart button.
		Button restartButton = new Button(main);
		restartButton.setText(buttonText);
		restartButton.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				mainActivity.restart(1000);
			}
		});
		
		
		RelativeLayout.LayoutParams buttonParam = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
		buttonParam.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		if (new MLString("a", "b").getName().equals("a")) {
			buttonParam.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
		} else {
			buttonParam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
		}
		
		button.setLayoutParams(buttonParam);
		
		
		RelativeLayout.LayoutParams nameParam = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
		if (new MLString("a", "b").getName().equals("b")) {
			nameParam.addRule(RelativeLayout.LEFT_OF, button.getId());
		} else {
			nameParam.addRule(RelativeLayout.RIGHT_OF, button.getId());
		}
		nameParam.addRule(RelativeLayout.ALIGN_PARENT_TOP);
		
		
		RelativeLayout.LayoutParams textParam = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
		textParam.addRule(RelativeLayout.BELOW, button.getId());

		textView.setLayoutParams(textParam);
		
		
		RelativeLayout.LayoutParams restartButtonParam = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
		restartButtonParam.addRule(RelativeLayout.CENTER_HORIZONTAL);
		restartButtonParam.addRule(RelativeLayout.BELOW, textView.getId());
		
		restartButton.setLayoutParams(restartButtonParam);
		
		
		addView(button);
		addView(textView);
		addView(restartButton);
	}

}